<template>
    <div>
        
        <!--老师添加-->
        <van-field label="标题" placeholder="请输入标题" v-model="form.title"></van-field>
        <van-field label="描述" placeholder="请输入" v-model="form.descip"></van-field>
        <van-field name="radio" label="状态">
                <template #input>
                    <van-radio-group v-model="form.status" direction="horizontal">
                        <van-radio name="1">免费</van-radio>
                        <van-radio name="2">收费</van-radio>
                    </van-radio-group>
                </template>
        </van-field>
        <van-field label="图片" placeholder="请输入" v-model="form.pic"></van-field>
        <select name="" id="" v-model="form.teacher_id">
            <option :value="i.id" v-for="i in teacherlist">{{i.name}}</option>
        </select>
        <reply :data='catelist'/>

        <div v-if="paramst" >
            <van-field v-for="(i,v) in paramst" :label="i" placeholder="请输入" v-model="value[i]"></van-field>    
        </div>
        {{value}}
        <van-button @click="add">添加</van-button>
    </div>
</template>

<script>
import reply from'./reply.vue'
import bus from './bus.js'
    export default {
        components:{
            "reply":reply
        },
        data() {
            return {
                radio:1,
                teacherlist:[{'id':1,'name':'李老师'},{'id':2,'name':'王老师'},{'id':3,'name':'张老师'}],
                catelist:[],
                paramst:{},
                form:{'pid':0,'params':'','status':2},
                value:{},
                
                
            }
        },
        methods: {
            //获取无线分类
            getcatelist(){
                this.$axios.get('/course/cates/').then(res=>{
                    this.catelist = {'pid':0,'name':'顶级父类','son':res.data.list}
                })
            },
            add(){
                //如果vulae有值传给params
                
                if(this.value){
                    
                    this.form.params = JSON.stringify(this.value)
                }
                this.$axios.post('/course/teaadd/',this.form).then(res=>{

                })
            }
        },
        mounted() {
            this.getcatelist()
            bus.$on('pid',res=>{
                this.form.pid = res
                this.$axios.get('/course/teaadd/?id='+res).then(res=>{
                    if(res.data.params){
                        this.paramst = JSON.parse(res.data.params)
                        
                    }else{
                        this.paramst = {}
                    }
                    
                })

            })
        },
    }
</script>

<style scoped>

</style>